<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        div {
            width: 200px;
            margin: 100px auto;
            border-bottom: 1px solid #ccc;
        }
        
        input {
            height: 30px;
            width: 170px;
            border: 0;
            outline: none;
        }
        
        img {
            height: 20px;
            width: 20px;
        }
    </style>
</head>

<body>
    <div>
        <input type="password" name="" id="">
        <img src="images/close.png" alt="">
    </div>

    <script>
        var btn = document.querySelector('img');
        var psw = document.querySelector('input');
        var flag = 1;

        btn.onclick = function() {
            if (flag == 1) {
                psw.type = 'text';
                btn.src = 'images/open.png';
                flag = 0;
            } else if (flag == 0) {
                psw.type = 'password';
                btn.src = 'images/close.png';
                flag = 1;

            }
        }
    </script>
</body>

</html>